package com.zhuzx;

import com.zhuzx.client.RpcConsumer;
import com.zhuzx.common.ConfigKeeper;
import com.zhuzx.common.registry.RpcRegistryHandler;
import com.zhuzx.register.handler.impl.ZookeeperRegistryHandler;
import com.zhuzx.service.UserService;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhuZX
 * @date 2021/1/31 11:25
 * @description
 */
@SpringBootApplication
public class ConsumerBoot {
    public static void main(String[] args) throws InterruptedException {
        Map<String, Object> instanceCacheMap = new HashMap<>();
        instanceCacheMap.put(UserService.class.getName(), UserService.class);

        ConfigKeeper.getInstance().setConsumerSide(true);
        // 启动一个定时的线程池，每隔xx秒开始自动上报统计数据到注册中心
        ConfigKeeper.getInstance().setInterval(5);

        RpcRegistryHandler rpcRegistryHandler = new ZookeeperRegistryHandler("127.0.0.1:2181");
        RpcConsumer consumer = new RpcConsumer(rpcRegistryHandler, instanceCacheMap);

        UserService userService = (UserService) consumer.createProxy(UserService.class);

        while (true) {
            Thread.sleep(2000);
            userService.sayHi("are you ok?");
        }
    }

}
